﻿
@{
    ViewData["Title"] = ViewBag.title;
    Layout = "~/Views/Shared/_LayoutPlugin.cshtml";
}
@section css{
    <style>
        .list-unstyled > li {
            padding: 10px;
        }
    </style>
}
<div id="tb">
    <input class="easyui-searchbox" data-options="prompt:'查询'" style="width:300px" />
    <button class="btn btn-info" id="btnAdd" onclick="add()"><i class="fa fa-plus"></i>新增</button>
    <button class="btn btn-info" id="btnEdit" onclick="update()"><i class="fa fa-pencil"></i>编辑</button>
    <button class="btn btn-info" id="btnDel" onclick="del()"><i class="fa fa-trash"></i>删除</button>
</div>
<table id="dg" toolbar="#tb"></table>
<div style="display:none">
    <div id="dlg">
        <form id="fm">
            <ul class="list-unstyled" style="padding:10px;">
                <li>
                    <label> input:</label><input class="easyui-textbox" style="width:200px;" />
                    <label> input:</label><input class="easyui-textbox" style="width:200px;" required="required" />
                </li>
                <li>
                    <label> input:</label><input class="easyui-numberbox" value="100" style="width:200px;" />
                    <label> input:</label><input class="easyui-timespinner" style="width:200px;" data-options="min:'08:30',showSeconds:true,editable:false,value:'12:00'" />
                </li>
                <li>
                    <label> input:</label><select class="easyui-combobox" style="width:200px;">
                        <option value="aa">a</option>
                        <option>b</option>
                        <option>c</option>
                    </select>
                    <label> input:</label><input class="easyui-datebox" style="width:200px;" data-options="value:'new Date()'" />
                </li>
            </ul>
        </form>
    </div>
    <div id="btns">
        <button class="btn btn-success" onclick="save()"><i class="fa fa-check"></i>保存</button>
        <button class="btn btn-primary" onclick="dlgClose()"><i class="fa fa-times"></i>关闭</button>
    </div>
</div>
@section js{
    <script>
        $(function () {
            $('#dg').datagrid({
                fit: true,
                //url: 'url',
                idField: 'id',
                rownumbers: true,
                singleSelect: true,
                autoRowHeight: false,
                pagination: true,
                striped: true,
                pageSize: 20,
                pageList: [10, 20, 50, 100],
                columns: [[
                    @foreach (var p in ViewBag.props)
                        {
                       <text>{ field: '@p.id', title: '@Html.Raw(p.text)', width: 100, align: 'center' },</text>
                        }
                ]]
            });
            $('#dlg').dialog({
                width: 600,
                height: 300,
                closed: true,
                closable: false,
                cache: false,
                draggable: true,
                resizable: true,
                modal: true,
                buttons: '#btns'
            })
        })
        function doSearch(value)
        {
            var obj = {};
            obj.filter = $.trim(value);
            $('#dg').datagrid('load', obj);
        }
        function add()
        {
            $('#dlg').dialog({ title: '新增' }).dialog('open');
        }
        function update()
        {
            var rows = $('#dg').datagrid('getChecked');
            //if (rows.length == 0) {
            //    $('#dg').datagrid('showTip', { position: 'left', content: '请选择' });
            //    return;
            //}
            $('#dlg').dialog({ title:'编辑' }).dialog('open');
            //todo
        }
        function save()
        {
            if (!$('#fm').form('validate'))
                return;
            var postdata = {}
            //todo
            $.ajax({
                //url: 'url',
                type: 'post',
                data: postdata,
                success: function (re) {
                    if (re.success) {
                        $('#dlg').dialog('close');
                        $('#dg').datagrid('load', {});
                        $.messager.info('提示', re.message);
                    }
                    else {
                        $.messager.alert('错误', re.message);
                    }
                }
            })
        }
        function dlgClose()
        {
            $('#dlg').dialog('close');
        }
        function del()
        {
            var row = $('#dg').datagrid('getSelected');
            if (row) {
                $.messager.confirm('确认', '是否确定要删除此记录?', function (r) {
                    if (r) {
                        $.post('url', { id: row.id }, function (data) {
                            if (data.success) {
                                $.messager.info('消息', '删除成功');
                                $('#dg').datagrid('reload').datagrid('clearChecked');
                            }
                            else { $.messager.alert('通知', data.message); }
                        });
                    }
                });
            }
        }
    </script>
}

